#!/bin/bash

original_dir=$(pwd)

cd /home/j30014474/桌面/sjk/jerryscript/

options="ENABLE_LTO ENABLE_O3 ENABLE_OFAST ENABLE_FOMIT_FRAME_POINTER ENABLE_FFAST_MATH ENABLE_FVISIBILITY_HIDDEN ENABLE_FNO_PLT ENABLE_FTREE_LOOP_IVCANON ENABLE_FTREE_VECTORIZE"

#options="ENABLE_LTO ENABLE_O3"

results_dict=""

for option in $options; do
    cmake_flags=""
    for single_option in $options; do
        if [ "$single_option" = "$option" ]; then
            cmake_flags="$cmake_flags -D$single_option=ON"
        else
            cmake_flags="$cmake_flags -D$single_option=OFF"
        fi
    done
    cmake $cmake_flags -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
    cmake --build .
    i=1
    while [ $i -le 5 ]; do
        echo "Testing $option, run $i"
        output=$(taskset -c 11 ./bin/jerry ../benchmarks/v8/combined.js)
        richards_result=$(echo "$output" | grep "RESULT Richards" | awk '{print $3}')
        deltablue_result=$(echo "$output" | grep "RESULT DeltaBlue" | awk '{print $3}')
        crypto_result=$(echo "$output" | grep "RESULT Crypto" | awk '{print $3}')
        raytrace_result=$(echo "$output" | grep "RESULT RayTrace" | awk '{print $3}')
        if [ -n "$results_dict" ]; then
            results_dict="$results_dict $option run $i: Richards=$richards_result, DeltaBlue=$deltablue_result, Crypto=$crypto_result, RayTrace=$raytrace_result"
        else
            results_dict="$option run $i: Richards=$richards_result, DeltaBlue=$deltablue_result, Crypto=$crypto_result, RayTrace=$raytrace_result"
        fi
        i=$(expr $i + 1)
    done
done

echo "$results_dict"

cd "$original_dir"
